def my_write():
    lst = ['张三', '李四', '王倩', '熊丽', ]
    with open('student.csv', 'w') as file:
        file.write(','.join(lst))  # 将列表转成字符串才能写入


def my_read():
    with open('student.csv', 'r') as file:
        s = file.read()
        lst = s.split(',')
        print(lst)


# 存储和读取二维数据
def my_write_table():
    lst = [
        ['商品名称', '单价', '采购数量'],
        ['冰箱', '6999', '100'],
        ['彩电', '3888', '500'],
    ]

    with open('table.csv', 'w', encoding='utf-8') as file:
        for item in lst:
            line = ','.join(item)
            file.write(line)
            file.write('\n')


def my_read_table():
    data = []
    with open('table.csv', 'r', encoding='utf-8') as file:
        lst = file.readlines()
        # print(lst)
        for item in lst:
            new_list = item[:len(item)-1].split(',')
            data.append(new_list)
    print(data)
    

if __name__ == '__main__':
    # my_write()
    # my_read()
    # my_write_table()
    my_read_table()
